package android.sdk;

import com.acelerometro.R;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;

public class SDKClientActivity extends Activity {

	private NetworkController network;
	private SensorController sensor;
	
    PowerManager.WakeLock wakeLock;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        
        PowerManager powerManager= (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Tesis");
        wakeLock.acquire();
        
        network = new NetworkController(this);
        sensor = new SensorController(this, network);

        setContentView(R.layout.main);

	}
	
	
	@Override
    protected void onResume() {
        super.onResume();
        wakeLock.acquire();
        sensor.onResume();
	}

	@Override
    protected void onPause() {
        super.onPause();
        wakeLock.release();
        sensor.onPause();
    }
    
    protected void onDestroy() {
        super.onDestroy();
        Log.i("Tesis", "onDestroy()");
        wakeLock.release();
        sensor.unregisterAccelerometerEvent();
    }


	public void registerAccelerometerEvent() {
		this.sensor.registerAccelerometerEvent();
	}


	public void unregisterAccelerometerEvent() {
		this.sensor.unregisterAccelerometerEvent();
	}
    
}
